﻿using System.Collections;
using System.Linq.Expressions;

namespace SimpleORM
{
    public class PagingTranslator : LambdaTranslator
    {
        #region Properties

        public IScriptFactory OrderByField { get; set; }
        public eOrder Order { get; set; }
        public int PageIndex { get; set; }
        public int PageSize { get; set; }

        #endregion

        #region Ctor

        public PagingTranslator()
        {
        }

        #endregion

        #region Methods

        #region Methods - Public

        public override void Translate(Expression expression)
        {
            MethodCallExpression m = expression as MethodCallExpression;

            this.Visit(m.Arguments[1]);
            //this.Visit(m.Arguments[2]);
            //this.Visit(m.Arguments[3]);
            //this.Visit(m.Arguments[4]);

            var items = Stack.ToList();

            OrderByField = items[0];

            Order = (eOrder)(m.Arguments[2] as ConstantExpression).Value;
            PageIndex = (int)(m.Arguments[3] as ConstantExpression).Value;
            PageSize = (int)(m.Arguments[4] as ConstantExpression).Value;
        }

        #endregion

        #region Methods - Visit

        #endregion

        #endregion
    }
}
